<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>

import {uploadPath} from "@/config/env";

export default {
    data() {
        return {
            obj: {},
            initSuccess: false,
            defaultData: {
                name: null,
                site: null,
                type: "user",
                visitState: "normal",
                ifHttps: "yes",
                httpsExpirationTime: null,
                remarks: null,
            },
        }
    },
    props: {
        uri: {},
    },
    computed: {
        option() {
            return {
                // size: "small",
                submitBtn: true,
                emptyBtn: true,
                submitText: '提交',
                emptyText: "关闭",
                column: [
                    {
                        label: '站点名称',
                        prop: 'name',
                        labelWidth: 110,
                        maxlength: 64,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 站点名称",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '站点地址',
                        prop: 'site',
                        labelWidth: 110,
                        maxlength: 256,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 站点地址",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '站点类型',
                        prop: 'type',
                        type: 'radio',
                        labelWidth: 110,
                        dicData: this.dict.get('SITE_TYPE'),
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请选择 站点类型",
                            trigger: "blur"
                        }]
                    },
                    // {
                    //     label: '访问状态',
                    //     prop: 'visitState',
                    //     type: 'radio',
                    //     labelWidth: 110,
                    //     dicData: this.dict.get('VISIT_STATE'),
                    //     span: 20,
                    //     rules: [{
                    //         required: false,
                    //         message: "请选择 访问状态",
                    //         trigger: "blur"
                    //     }]
                    // },
                    {
                        label: '是否配置 https',
                        prop: 'ifHttps',
                        type: 'radio',
                        labelWidth: 110,
                        dicData: this.dict.get('IF_HTTPS'),
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请选择 是否配置 https",
                            trigger: "blur"
                        }]
                    }, {
                        label: '正常 codes',
                        prop: 'normalCodes',
                        labelWidth: 110,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请填写正常 codes",
                            trigger: "blur"
                        }]
                    },
                    // {
                    //     label: 'https 过期时间',
                    //     prop: 'httpsExpirationTime',
                    //     type: 'datetime',
                    //     labelWidth: 110,
                    //     format: 'YYYY-MM-DD HH:mm:ss',
                    //     valueFormat: 'YYYY-MM-DD HH:mm:ss',
                    //     span: 20,
                    //     rules: [{
                    //         required: false,
                    //         message: "请选择 https 过期时间",
                    //         trigger: "blur"
                    //     }]
                    // },
                    {
                        label: '备注',
                        prop: 'remarks',
                        labelWidth: 110,
                        maxlength: 256,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请输入 备注",
                            trigger: "blur"
                        }]
                    },

                ]
            }
        }
    },
    created() {
        this.obj = this.defaultData;
        this.initSuccess = true;
    },
    methods: {
        emptytChange() {
            this.$emit('closeDialog', false);
        },
        submit(form, done) {
            this.crud.post(this.uri.info, this.obj).then((res) => {
                if (res.data.code == 200) {
                    this.$emit('closeDialog', true);
                }
                done(form);
            }).catch((err) => {
                console.error(err);
                done(form);
            })
        },
    }
}
</script>
